using UnityEngine;

public class OnChargeExplosionAdhesive : OnChargeExplosion
{
	public override void OnCollisionEnter(Collision collision)
	{
		if (settings.offlineMode)
		{
			base.gameObject.transform.SetParent(collision.gameObject.transform);
		}
		GetComponent<Rigidbody>().isKinematic = true;
		RaycastHit hitInfo;
		if (Physics.Raycast(base.transform.position, collision.contacts[0].normal * -1f, out hitInfo))
		{
			base.gameObject.transform.rotation = Quaternion.LookRotation(hitInfo.normal);
			base.gameObject.transform.position = hitInfo.point;
		}
		base.transform.localScale = Vector3.one;
		base.transform.localScale = new Vector3(1f / base.transform.lossyScale.x, 1f / base.transform.lossyScale.y, 1f / base.transform.lossyScale.z);
		objCollider.enabled = false;
		PhotonView photonView = NGUITools.FindInParents<PhotonView>(collision.gameObject.transform);
		if (photonView != null)
		{
			base.gameObject.transform.SetParent(collision.gameObject.transform);
			RPC("AttachToParent", PhotonTargets.AllBuffered, photonView.viewID, base.transform.parent.name, base.transform.localPosition, base.transform.localRotation);
		}
		TrailRenderer component = GetComponent<TrailRenderer>();
		if (component != null)
		{
			component.enabled = false;
		}
	}

	[PunRPC]
	protected virtual void AttachToParent(int setId, string parentName, Vector3 localPosition, Quaternion localRotation)
	{
		PhotonView photonView = PhotonView.Find(setId);
		if (photonView != null && !string.IsNullOrEmpty(parentName))
		{
			if (photonView.isMine && parentName == "Player(Clone)")
			{
				parentName = "MyPlayer_____";
			}
			base.transform.SetParent(FindChildCustom(parentName, photonView.transform));
			base.transform.localPosition = localPosition;
			base.transform.localRotation = localRotation;
			GetComponent<PhotonTransformView>().enabled = false;
		}
		TrailRenderer component = GetComponent<TrailRenderer>();
		if (component != null)
		{
			component.enabled = false;
		}
	}

	private Transform FindChildCustom(string name, Transform t)
	{
		if (t.name == name)
		{
			return t;
		}
		foreach (Transform item in t)
		{
			Transform transform = FindChildCustom(name, item);
			if (transform != null)
			{
				return transform;
			}
		}
		return null;
	}
}
